<?php

	// TITLE: Person_phone AUTO MODEL
	// FILE: scaffolding/model/person_phone.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createPersonPhone = function($con, $personPhone) {
		$sql = 'INSERT INTO person_phone (person_id, phone_id) VALUES (';
		$sql .= $person_phone->getPersonId() . ', ';
		$sql .= $person_phone->getPhoneId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readPersonPhone = function($con, $id) {
		$sql = 'SELECT * FROM person_phone WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$personPhone = new PersonPhone();
			$personPhone->setPersonId($dbio->select($readPerson(result[0])));
			$personPhone->setPhoneId($dbio->select($readPhone(result[1])));
		} else {
			$personPhone = false;
		}
		return $personPhone;
	};

	$updatePersonPhone = function($con, $personPhone) {
		$sql = 'UPDATE person_phone SET ';
		$sql .= 'person_id = ' . $person_phone->getPersonId() . ', ';
		$sql .= 'phone_id = ' . $person_phone->getPhoneId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deletePersonPhone = function($con, $id) {
		$sql = 'DELETE FROM person_phone WHERE person_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listPersonPhone = function($con) {
		$sql = 'SELECT * FROM person_phone';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$personPhones = array();
			while ($result = mysqli_fetch_array($results)) {
				$personPhone = new PersonPhone();
				$personPhone->setPersonId($dbio->select($readPerson(result[0])));
				$personPhone->setPhoneId($dbio->select($readPhone(result[1])));
				$personPhones[] = personPhone;
			}// end while
		} else {
			$personPhones = false;
		}
		return $personPhones;
	};

